<%@ page import="com.test.tagtest.City" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/9/9
  Time: 14:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>formtag</title>
</head>
<body>
<%
    List<City> cities = new ArrayList<>();
    cities.add(new City(1001, "AA"));
    cities.add(new City(1002, "BB"));
    cities.add(new City(1003, "CC"));
    cities.add(new City(1004, "DD"));
    request.setAttribute("cities", cities);
%>
<%--
表单标签：
1.使用和html的form标签的感觉差不多
2.struts2的form标签会生成一个table，进行自动的排版
3.可以对表单提交进行自动回显:从栈顶对象开始匹配属性，并把匹配的属性值赋到对应的标签的value中，若栈顶对象没有对应的属性，则依次向下找相对应的属性
--%>
<s:debug/>
<s:form action="save">
    <s:hidden name="userId"/>
    <s:textfield name="userName" label="UserName"/>
    <s:password name="password" label="Password"/>
    <s:textarea name="desc" label="Desc"/>

    <s:checkbox name="married" label="Married"/>

    <s:radio name="gender" list="#{'1':'male','0':'female'}" label="Gender"/>

    <%--服务端需要使用集合类型，以保证能够进行正常的回显--%>
    <s:checkboxlist name="cities" list="#request.cities"
                    listKey="cityId" listValue="cityName"
                    label="City"/>

    <s:select list="{11,12,13,14,15,17,18,19,20}"
              headerKey=""
              headerValue="请选择"
              name="age"
              label="Age">
        <%--
            s:optgourp可以用作s:select显示更多的下拉框
            注意：必须有键值对，而不能使用一个集合，让其值既作为键，也作为值
        --%>
        <s:optgroup label="21-30" list="#{21:21,25:40}"></s:optgroup>
        <s:optgroup label="31-40" list="#{31:31}"></s:optgroup>
    </s:select>

    <s:submit/>
</s:form>
<hr/>
<form action="save.action" method="post">
    Married:<input type="checkbox" name="married">
    <input type="submit" value="Submit">
</form>
</body>
</html>
